package io;

import java.io.BufferedOutputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class FlushDemo {
    public static void main(String[] args) throws IOException {
        FileOutputStream fos=new FileOutputStream("note1.txt");
        BufferedOutputStream bos=new BufferedOutputStream(fos);
        String line="每天都在升国旗,我是少时诵诗书所";
        byte[]data=line.getBytes(StandardCharsets.UTF_8);
        bos.write(data);
        bos.flush();
        System.out.println("数据写出完毕");
        bos.close();//缓冲流关闭时会自动调用一次flush方法,确保所有数据都会写出


    }
}
